package com.project.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.entity.qo.ImgQo;
import com.project.entity.qo.MenuQo;
import com.project.entity.vo.MenuVo2;
import com.project.result.ResponseResult;
import com.project.service.MenuService;
import com.project.entity.vo.MenuVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author qjj
 * @create 2022/3/29 12:16
 */
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Resource
    private MenuService menuService;


    /**
     * 获取菜单
     * @return 所有菜品
     */
    @GetMapping("/menu/list")
    public ResponseResult<List<MenuVo>> selectMenuList(){
        List<MenuVo> menuVos = menuService.selectMenuList();
        return ResponseResult.success(menuVos);
    }

    /**
     * 分页查询
     * @param current 当前页
     * @return 返回对应的菜
     */
    @GetMapping("/select/page/menu")
    public ResponseResult<Page<MenuVo2>> selectPageMenu(Integer current){
        return menuService.selectMenuPage(current);
    }

    /**
     * 根据类型查询或者根据菜的id查询
     * @param type 类型值或者id
     * @return 对应的菜品
     */
    @GetMapping("/select/menu/type")
    public ResponseResult<List<MenuVo>> selectMenuByType(Integer type,Long menuId){
        return menuService.selectMenuByType(type,menuId);
    }

    /**
     * 删除图片
     * @param imgId
     * @return
     */
    @DeleteMapping("/delete/img")
    public ResponseResult<String> deleteImg(Long imgId){
        return menuService.deleteImg(imgId);
    }

    /**
     * 添加图片
     * @param imgQo
     * @return
     */
    @PostMapping("/add/img")
    public ResponseResult<String> addImg(ImgQo imgQo){
        return menuService.addImg(imgQo);
    }

    /**
     * 编辑菜
     * @param menuQo
     * @return
     */
    @PostMapping("/update/menu")
    public ResponseResult<String> updateMenu(@RequestBody MenuQo menuQo){
        return menuService.updateMenu(menuQo);
    }

    /**
     * 是否售空，0代表售空，1代表正常，2代表审核中
     * @param menuQo
     * @return
     */
    @PostMapping("/update/status")
    public ResponseResult<String> updateStatus(@RequestBody MenuQo menuQo){
        return menuService.updateStatus(menuQo);
    }

    /**
     * 添加新菜品
     * @param menuQo
     * @return
     */
    @PutMapping("/add/menu")
    public ResponseResult<String> addMenu(@RequestBody MenuQo menuQo){
        return menuService.addMenu(menuQo);
    }

    /**
     * 删除菜品
     * @param id
     * @return
     */
    @DeleteMapping("/delete/menu")
    public ResponseResult<String> deleteMenu(@RequestParam("id") List<Long> id){
        return menuService.deleteMenu(id);
    }

    /**
     * 点赞
     * @param menuId
     * @return
     */
    @PostMapping("/add/praise")
    public ResponseResult<String> addPraiseNumber(Long menuId){
        return menuService.addPraiseNumber(menuId);
    }

    /**
     * 根据状态查询
     * @param status
     * @return
     */
    @GetMapping("/select/by/status")
    public ResponseResult<List<MenuVo>> selectMenuBystatus(Integer status){
        List<MenuVo> menuVos = menuService.selectMenuBystatus(status);
        return ResponseResult.success(menuVos);
    }

    /**
     * 根据点赞排行
     * @return
     */
    @GetMapping("/select/ranking")
    public ResponseResult<List<MenuVo>> rankingList(){
        return menuService.rankingList();
    }

    /**
     * 根据名字模糊查询
     * @param name
     * @return
     */
    @GetMapping("/select/menu/by/name")
    public ResponseResult<List<MenuVo>> selectMenuByName(String name){
        return menuService.selectMenuByName(name);
    }
}
